package com.kantboot.user.account.web.controller;

import com.kantboot.global.rest.result.CommonSuccessStateCodeAndMsg;
import com.kantboot.user.account.service.IUserAccountService;
import com.kantboot.util.common.result.RestResult;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user-account-web/userAccount")
public class UserAccountController {

    @Resource
    private IUserAccountService service;

    /**
     * 获取自己的用户账号
     * @return 自身的用户账号信息
     */
    @RequestMapping("/getSelf")
    public RestResult<Object> getSelf() {
        return RestResult.success(service.getSelf(), CommonSuccessStateCodeAndMsg.GET_SUCCESS);
    }

    /**
     * 修改密码
     */
    @RequestMapping("/changePassword")
    public RestResult<Void> changePassword(
            @RequestParam("oldPassword") String oldPassword,
            @RequestParam("newPassword") String newPassword) {
        service.changePassword(oldPassword, newPassword);
        return RestResult.success(null, CommonSuccessStateCodeAndMsg.CHANGE_SUCCESS);
    }

    /**
     * 判断是否存在手机号
     */
    @RequestMapping("/existsByPhone")
    public RestResult<Boolean> existsByPhone(
            @RequestParam("phoneAreaCode") String phoneAreaCode,
            @RequestParam("phone") String phone) {
        return RestResult.success(service.existsByPhone(phoneAreaCode, phone), CommonSuccessStateCodeAndMsg.GET_SUCCESS);
    }

}
